<nav  class="top" th:fragment="html">
    <div id="topDiv" class="bg-primary">
        &nbsp;&nbsp;
        <a href="/view/follow/index">
            <span style="margin:0px" class="glyphicon redColor"></span>
            我的
        </a>
        &nbsp;&nbsp;
        <a href="/view/fund/index">
            <span style="margin:0px" class="glyphicon redColor"></span>
            基金管理
        </a>
        &nbsp;&nbsp;
        <a href="/view/user/index">
            <span style="margin:0px" class="glyphicon redColor"></span>
            用户管理
        </a>

        <span class="pull-right">
		    <span style="color:#F0AD4E;">{{topUser.userName}}</span>&nbsp;&nbsp;
		    <a href="#nowhere" @click="userlogout">
                退出
            </a>&nbsp;&nbsp;
	    </span>

    </div>


    <script>
        var storage=window.localStorage;
        $(function(){
            var topVue={
                topUser:{userId:'',userName:''}
            };
            var vue=new Vue({
                el: '#topDiv',
                data: topVue,
                mounted: function () {
                    this.$nextTick(function () {
                        this.initUser();
                    });
                },
                methods: {
                    initUser:function(){
                        vue.topUser.userId=storage.getItem("fan_userId");
                        vue.topUser.userName=storage.getItem("fan_userName");
                    },
                    userlogout:function () {
                        console.log("tuichu!");
                        var url = "/users/logout";
                        axios.get(url).then(function (response) {
                            var result = response.data;
                            if(result.code==0){
                                storage.removeItem("fan_access_token");
                                storage.removeItem("fan_userId");
                                storage.removeItem("fan_userName");

                                vue.clearCookie("token");

                                location.href="/view/login";
                            }else{
                                alert(result.msg);
                            }
                        });
                    },
                    clearCookie:function (cname) {
                        var d = new Date();
                        d.setTime(d.getTime() -1);
                        var expires = "expires="+d.toUTCString();
                        document.cookie = cname + "=;path=/;" + expires;
                    },
                },
            });
        });
    </script>

    <style>
        div#topDiv {
            padding-top: 5px;
            padding-bottom: 6px;
        }
        div#topDiv a {
            color: white;
        }
        div#topDiv span {
            color: #f0ad4e;
            font-weight: bold;
        }
    </style>

</nav>

